package com.colin.project.controller;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

/**
 * 路由控制层
 */
@Controller
public class RouterController implements InitializingBean {

    private List<Integer> ageList;

    /**
     * 去往注册页面
     *
     * @return register.html
     */
    @RequestMapping("/toRegister")
    public String toRegister() {
        return "register";
    }

    /**
     * 去往登录页面
     *
     * @return login.html
     */
    @RequestMapping("/toLogin")
    public String toLogin() {
        return "login";
    }

    /**
     * 去往忘记密码界面
     * @return
     */
    @RequestMapping("/toForgetPassword")
    public String toForgetPassword() {
        return "forgetPassword";
    }

    /**
     * 去往更改密码界面
     * @param email
     * @param model
     * @return
     */
    @RequestMapping("/toChangePassword/{email}")
    public String toChangePassword(
            @PathVariable("email") String email,
            Model model
    ) {
        model.addAttribute("email", email);
        return "changePassword";
    }

    /**
     * 去往个人中心界面
     * @param model
     * @return
     */
    @RequestMapping("/toPersonalCenter")
    public String toPersonalCenter(Model model) {
        model.addAttribute("ageList", ageList);
        return "personalCenter";
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        this.ageList = new ArrayList<>();
        for (int i = 18; i < 61; i++) {
            ageList.add(i);
        }
    }

    /**
     * 去往视频上传界面
     * @return
     */
    @RequestMapping("/toVideoUpload")
    public String toVideoUpload() {
        return "videoUpload";
    }
}
